<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script> 
       //可以根据不同的触发条件，通知不同的观察者，而不是通知全部观察者
       //list      仓库: 存放订阅者
       //publish   发布
       //subscribe 订阅

       //调度中心
       const PubSub = {
          list: [],
          publish(){
            this.list.forEach(item => item())
          },
          subscribe(cb){
            this.list.push(cb);
          }
       }
 

       function testA(){
         console.log('testA');
       }

       function testB(){
         console.log('testB');
       }

       PubSub.subscribe(testA)
       PubSub.subscribe(testB)

       PubSub.publish();
    </script>
</body>
</html>